<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            height: 200px;
            width: 200px;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <div id="dv">
        <h1>这是h1标签</h1>
        <span>这是span标签</span>
        <p>这是p标签</p>
    </div>
    <input type="button" value="点击改变P标签颜色" id="bn">
    <script>
        function my$(id) {
            return document.getElementById(id);
        }
        var divObjet = my$("bn");
        divObjet.onclick = function () {
            //获取子元素
            var childObjets = my$("dv").children;
            for (const childObjet of childObjets) {
                if (childObjet.nodeName == "P") {
                    childObjet.style.backgroundColor = "red";
                }
            }
        }

    </script>
</body>

</html>